package definition;

import domain.User;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Bean 的实例化
 * @author jackcfan
 * @date 2021/9/12
 */
public class BeanInstantiationTest {

    @Test
    public void test(){
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("bean-instantiation-*.xml");
        User user = beanFactory.getBean("user-by-static-method", User.class);
        User userByInstanceMethod = beanFactory.getBean("user-by-instance-method", User.class);
        User userByFactoryBean = beanFactory.getBean("user-by-factory-bean", User.class);
        System.out.println(user);
        System.out.println(userByInstanceMethod);
        System.out.println(userByFactoryBean);

        System.out.println("user != userByInstanceMethod "+(user != userByInstanceMethod));
        System.out.println("user != userByFactoryBean "+(user != userByFactoryBean));
    }
}
